import { AuthStore } from "@/stores/modules/auth";
import { createRouter, createWebHistory } from "vue-router";
import guard from "./guard";

import routes from "@/router/modules";

const router = createRouter({
	history: createWebHistory(import.meta.env.BASE_URL),
	routes: routes,
	strict: true,
	scrollBehavior(to, from, savedPosition) {
		if (savedPosition) {
			return savedPosition;
		} else {
			return { top: 0 };
		}
	}
});
router.resetRouter = () => {
	const authStore = AuthStore();
	authStore.flatMenuListGet.forEach(route => {
		const { name } = route;
		if (name && router.hasRoute(name)) router.removeRoute(name);
	});
};

guard(router);
export default router;
